/*
 * Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
 */
package com.pitop.factory.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import com.pitop.factory.api.FactorySampleFeignApi;
import com.pitop.core.exceptions.FactorySampleException;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.entity.Page;
import com.pitop.factory.entity.FactorySample;


/**
 * 工厂的样品
 *
 * @author pi-top
 */
@Service("factorySampleSVImpl")
@Slf4j
public class FactorySampleSVImpl {

    @Autowired
    private FactorySampleFeignApi factorySampleFeignApi;

    /**
     * 加载一个对象FactorySample
     *
     * @param id id* @param sampleCode 样品编码* @param factoryCode 工厂编码
     * @return FactorySample
     */
    public FactorySample load(java.lang.Long id, java.lang.String sampleCode, java.lang.String factoryCode) {
        if (id == null && sampleCode == null && factoryCode == null) {
            throw new FactorySampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return factorySampleFeignApi.load(id, sampleCode, factoryCode);
    }

    /**
     * 加载一个对象FactorySample 通过id
     *
     * @param id id
     * @return FactorySample
     */
    public FactorySample loadById(java.lang.Long id) {
        if (id == null) {
            throw new FactorySampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return factorySampleFeignApi.loadById(id);
    }

    /**
     * 加载一个对象FactorySample 通过sampleCode
     *
     * @param sampleCode 样品编码
     * @return List<FactorySample>
     */
    public List<FactorySample> listBySampleCode(java.lang.String sampleCode) {
        if (sampleCode == null) {
            throw new FactorySampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return factorySampleFeignApi.listBySampleCode(sampleCode);
    }

    /**
     * 加载一个对象FactorySample 通过factoryCode
     *
     * @param factoryCode 工厂编码
     * @return List<FactorySample>
     */
    public List<FactorySample> listByFactoryCode(java.lang.String factoryCode) {
        if (factoryCode == null) {
            throw new FactorySampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return factorySampleFeignApi.listByFactoryCode(factoryCode);
    }


    /**
     * 删除对象FactorySample
     *
     * @param id id* @param sampleCode 样品编码* @param factoryCode 工厂编码
     * @return FactorySample
     */

    public void delete(java.lang.Long id, java.lang.String sampleCode, java.lang.String factoryCode) {
        if (id == null && sampleCode == null && factoryCode == null) {
            throw new FactorySampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        factorySampleFeignApi.delete(id, sampleCode, factoryCode);
    }


    /**
     * 查询FactorySample分页
     *
     * @param factorySample 对象
     * @param curPage       当前页
     * @param pageSize      分页条数
     * @return List<FactorySample>
     */
    public List<FactorySample> list(FactorySample factorySample, int curPage, int pageSize) {
        return factorySampleFeignApi.list(factorySample, curPage, pageSize);
    }

    /**
     * 查询FactorySample分页
     *
     * @param id       id* @param sampleCode  样品编码* @param factoryCode  工厂编码
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<FactorySample>
     */
    public List<FactorySample> list(java.lang.Long id, java.lang.String sampleCode, java.lang.String factoryCode, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        FactorySample factorySample = new FactorySample();
        factorySample.setId(id);
        factorySample.setSampleCode(sampleCode);
        factorySample.setFactoryCode(factoryCode);

        return factorySampleFeignApi.list(factorySample, curPage, pageSize);
    }


    public int count(java.lang.Long id, java.lang.String sampleCode, java.lang.String factoryCode) {
        return factorySampleFeignApi.count(id, sampleCode, factoryCode);
    }


    public int count(FactorySample factorySample) {
        return factorySampleFeignApi.count(factorySample);
    }


    /**
     * 保存
     *
     * @param factorySample 实体
     * @throws BaseException
     */
    public void save(FactorySample factorySample) {
        if (factorySample == null) {
            throw new FactorySampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        factorySampleFeignApi.build(factorySample);
    }

    /**
     * 更新
     *
     * @param factorySample 实体
     * @throws BaseException
     */
    public void modify(FactorySample factorySample) {
        if (factorySample == null) {
            throw new FactorySampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        factorySampleFeignApi.modify(factorySample);
    }

}
